--当前需要购买的物品和价格
currentItem=nil
nextIdx=1

local settingItemIdList = {
  {
    ['itemID']=173202,
    ['itemName']='萦亡布',
    ['unitPrice']=1.5*10000,
  },
  {
    ['itemID']=172089,
    ['itemName']='荒革',
    ['unitPrice']=2.5*10000,
  },
  {
    ['itemID']=172092,
    ['itemName']='苍骨',
    ['unitPrice']=0.4*10000,
  },
}


--/dump C_AuctionHouse.GetCommoditySearchResultInfo(173202,1)

function getFirstRowCount()

  local info = C_AuctionHouse.GetCommoditySearchResultInfo(currentItem.itemID,1)
  --info is nil
  return info and info.quantity or 1
end

--/run scanItemID()
function scanItemID()
  print("StartCommoditiesPurchase")
  currentItem = settingItemIdList[nextIdx]
  nextIdx = nextIdx+1
  if nextIdx>#settingItemIdList then
    nextIdx=1
  end
  C_AuctionHouse.StartCommoditiesPurchase(currentItem.itemID,getFirstRowCount())
end

local frame =CreateFrame("Frame")
frame:RegisterEvent("COMMODITY_PRICE_UPDATED")
frame:SetScript("OnEvent",function(self,event,...)
  local unitPrice,allPrice=...
  print(currentItem.itemID,currentItem.itemName,event,...)

  if unitPrice<=currentItem.unitPrice then
    print("购买",currentItem.itemID,"单价=",unitPrice/10000)
    C_AuctionHouse.ConfirmCommoditiesPurchase(currentItem.itemID,getFirstRowCount())
  else
    print("价格过高，不购买",currentItem.itemID,"单价=",unitPrice/10000)
  end
end)

--C_Timer.NewTicker(3, function()
--  scanItemID()
--end) 作者：老胡聊聊天 https://www.bilibili.com/read/cv14704004/?from=readlist 出处：bilibili